import React, { Component } from 'react'

export class Demo3_setState_add_callback extends Component {
    state={
        x:1
    }
  render() {
    return (
    
      <div>
          <div>Demo3_setState_add_callback{this.state.x}</div>

          <button onClick={()=>{
            for(let i=0; i<19;i++){
              this.setState(
                prestate=>{
                  console.log(prestate);
                  
                return {
                  x: prestate.x+1
                }})
            

          }}}>点击累加</button>

      </div>
    )
  }
}

export default Demo3_setState_add_callback


//setState传递函数
/*
this.setState((preState,nextState)=>{

    //preState是之前的状态

    
    
    
    
    })




*/